home *** CD-ROM | disk | FTP | other *** search
/ Aminet 7 / Aminet 7 - August 1995.iso / Aminet / text / tex / UsingLaTeX21.lha / UsingLatex / mf / rexx / MakeTeXFont.rexx next >
Encoding:
OS/2 REXX Batch file  |  1995-04-25  |  13.5 KB  |  492 lines

  1. /*
  2. ** AREXX $VER: MakeTeXFont 42.3 (25.4.95)
  3. **
  4. ** Send new features and bug reports to 
  5. **
  6. ** Martin Bokaemper
  7. ** Reuthstr. 12
  8. ** 91099 Poxdorf
  9. ** Germany
  10. **
  11. ** Email: mnbokaem@cip.e-technik.uni-erlangen.de (Internet)
  12. **        mab@ame.zer (Zerberus)
  13. **
  14. ** Ulrich Wisser
  15. ** Heerstr. 125
  16. ** 53111 Bonn
  17. **
  18. ** HISTORY:
  19. **
  20. ** 0.80: My 'works-fine-for-me' version modified by Georg Hessmann 13.04.91
  21. **       + Variables for all directories and filenames
  22. **       + ^C and ^D detection 
  23. **       + support for a 'modefile' containing site-specific information
  24. **       + searches for standard magsteps 
  25. **       + support for different format-files
  26. **
  27. ** 0.81: + take new Parameters 'drivertype' and 'pkfilename' 
  28. **       Georg Hessmann 17.04.91
  29. **
  30. ** 0.82: + History 
  31. **       + a lot of small improvements and bugfixes
  32. **       + looking for PK-directory for each device 
  33. **       + checking if the font already exists
  34. **       Martin Bokaemper 21.04.91
  35. **
  36. ** 0.84: + add new parameter 'pkdir' (new since driver version V1.10)
  37. **       Georg Hessmann 09.06.91
  38. **
  39. ** 0.85: + fixed a pkdir/pkfilename mixing bug
  40. **       + slight modifications, now works with old driver versions
  41. **       + changed exit codes
  42. **       + always calls uses plain.base (absolutely no gain in using cmbase)
  43. **       J\"org H\"ohle 24.6.91, 01.08.91
  44. **
  45. ** 0.86: + fixed makedir(pkname) bug
  46. **       J\"org H\"ohle 06.08.91
  47. **
  48. ** 0.90: + add makedir(pkdir)
  49. **       + delete localfont entry in 'modes' file
  50. **       Georg Hessmann 28.08.91
  51. **
  52. ** 1.00: + only one logfile entry per call
  53. **       + ERROR: now reports interpreted sourceline
  54. **       + fonts can be copied to mf:<mode> for font-caching
  55. **       + magstep calculation improved.  now same as in ShowDVI/DVIPrint
  56. **       + MISSING: \scrollmode correctly inserted
  57. **       Ulrich Wisser 25.08.92
  58. **
  59. ** 1.01: + bumped revision number because of partial integration of
  60. **       + versions 0.91 and 1.0 and some personal modifications.
  61. **       Andreas Scherer 31.10.93
  62. **
  63. ** 42.0: + Changed slightly so that the .pk file doesn't end up
  64. **         in TeX:pk/ but in TeX:pk/xresxyres/
  65. **       + 'dc' fonts now use 'dx.base'; all others use old 'plain.base'.
  66. **       Jörgen Grahn 19.10.94
  67. **
  68. ** 42.1: + Commented out the renaming to TeX:pk/xresxyres/ - MakeTeXFont
  69. **         reads that information from MF:config/modes, so you're better off
  70. **         changing that file.
  71. **       + Removed the silly filenote and the protection bits.
  72. **       + Did another change, preventing generation of files like
  73. **         TeX:pk/360x360/360/dcr10.360pk
  74. **       + Errorlevel 10 from virmf isn't fatal. Changed that.
  75. **         That's acually a bugfix - originally any return>0 aborted the script.
  76. **       Jörgen Grahn 20.10.94
  77. **
  78. ** 42.2: + Incorporated different magstep calculation algorithm from
  79. **         MakeTeXFont 0.91 to allow negative magsteps for the DviDvi
  80. **         tool
  81. **       Jörgen Grahn 18.4.95
  82. **
  83. ** 42.3: + Added a bell sound at the end so that you can hear when MetaFont
  84. **         is finished.
  85. **       Jörgen Grahn 25.4.95
  86. **
  87. */
  88.  
  89. Options Failat 15    /* JöG */
  90.  
  91. Signal On FAILURE   /* JöG */
  92. Signal On BREAK_C
  93. Signal On BREAK_D
  94.  
  95. /*
  96. ** Files / Directories
  97. */
  98. LOGDIR       = "MF:log"                 /* directory of the logfiles    */
  99.                                         /* without trailing slash!      */
  100. LOGNAME      = LOGDIR"/MakeTeXFont.log" /* logfile                      */
  101. PKDIR        = "TeX:pk/"                /* Where pk fonts are copied to */
  102. MODEFILENAME = "MF:config/modes"        /* description of the modes     */
  103. TEXTFM       = "TeX:fonts/"             /* TeX tfm-files directory      */
  104. VIRMF        = "MF:bin/VirMF"
  105. GFTOPK       = "MF:bin/GFtoPK"
  106. FONTFILENAME = "TeX:config/fontvols"
  107.  
  108. /*
  109. ** Bases. Put in others, if you like.
  110. */
  111. NORMALBASE = "plain"
  112.  
  113. /*
  114.  * Arguments. MakeTeXFont seems to ignore 'PKDIR' and 'DRIVERTYPE'. [JöG]
  115.  * [Should that read "...'PKFILENAME' and 'DRIVERTYPE'" ? JöG at a later time.]
  116.  *
  117.  */
  118. Parse Arg FNTNAME DPI HBASEDPI VBASEDPI DRIVERTYPE PKFILENAME PKDIR .
  119.  
  120. Say "Making font "FNTNAME" at "DPI" dpi and base ("HBASEDPI","VBASEDPI")"
  121. Say "Driver" DRIVERTYPE "filename" PKFILENAME "directory" PKDIR
  122.  
  123. If ~Show('Libraries','rexxsupport.library') Then Do
  124.   If ~AddLib('rexxsupport.library',0,-30) Then Do
  125.      Say "No RexxSupport.library ... No Metafont!"
  126.      Exit 5
  127.   End
  128. End
  129.  
  130. DUMMY = Time("Reset")
  131.  
  132. If ~Exists(LOGDIR) Then Do
  133.   Address COMMAND 'MakeDir 'LOGDIR
  134.   If ~Exists(LOGDIR) Then Do
  135.     Call Log("Could not create logdir="LOGDIR)
  136.     Exit 5
  137.   End
  138.   Say "logfile-directory ("LOGDIR"/) did not exist. It was created."
  139. End
  140.  
  141. If ~Exists(LOGNAME) Then Do
  142.   Address COMMAND 'echo >'||LOGNAME
  143.   If ~Exists(LOGNAME) Then Do
  144.     Call Log("Could not create logfile="LOGDIR"/"LOGNAME)
  145.     Exit 5
  146.   End
  147.   Say "logfile did not exist. It was created."
  148. End
  149.  
  150. FNTNAME    = Translate(FNTNAME,XRange('a','z'),XRange('A','Z')) /* lower */
  151. DPI        = Strip(DPI)
  152. HBASEDPI   = Strip(HBASEDPI)
  153. VBASEDPI   = Strip(VBASEDPI)
  154. DRIVERTYPE = Translate(DRIVERTYPE,XRange('a','z'),XRange('A','Z')) /* lower */
  155. PKFILENAME = Translate(PKFILENAME,XRange('a','z'),XRange('A','Z')) /* lower */
  156. PKDIR      = Translate(PKDIR,XRange('a','z'),XRange('A','Z')) /* lower */
  157.  
  158.  
  159. /*
  160. ** Changed 19.07.92 by Ulrich Wisser
  161. ** Needed to calculate correct DPI sizes
  162. */
  163. Numeric DIGITS 12
  164.  
  165. /* Magstep calculation algorithm changed here to allow negative
  166.  * magsteps, needed for the dvidvi utility.
  167.  * Algorithm from MakeTeXFont 0.91 (Jochen Wiedmann)
  168.  * Incorporated in v42.2 1995-04-18 (JöG)
  169.  *
  170.  */
  171.  
  172. mag   = dpi/hbasedpi    /* what magstep should the font have? */
  173.  
  174. magmult.0      = 21    /* number of saved magsteps */
  175.  
  176. MAGMULT.NUM.1  = 1.0           /* MagStep(0)   */
  177. MAGMULT.STR.1  = "0"
  178. MAGMULT.NUM.2  = 1.09544511501 /* MagStep(0.5) */
  179. MAGMULT.STR.2  = "0.5"
  180. MAGMULT.NUM.3  = 1.2           /* MagStep(1)   */
  181. MAGMULT.STR.3  = "1"
  182. MAGMULT.NUM.4  = 1.31453413801 /* MagStep(1.5) */
  183. MAGMULT.STR.4  = "1.5"
  184. MAGMULT.NUM.5  = 1.44          /* MagStep(2)   */
  185. MAGMULT.STR.5  = "2"
  186. MAGMULT.NUM.6  = 1.57744096561 /* MagStep(2.5) */
  187. MAGMULT.STR.6  = "2.5"
  188. MAGMULT.NUM.7  = 1.728         /* MagStep(3)   */
  189. MAGMULT.STR.7  = "3"
  190. MAGMULT.NUM.8  = 2.0736        /* MagStep(4)   */
  191. MAGMULT.STR.8  = "4"
  192. MAGMULT.NUM.9  = 2.48832       /* MagStep(5)   */
  193. MAGMULT.STR.9  = "5"
  194. MAGMULT.NUM.10 = 2.985984      /* MagStep(6)   */
  195. MAGMULT.STR.10 = "6"
  196. MAGMULT.NUM.11 = 3.5831808     /* MagStep(7)   */
  197. MAGMULT.STR.11 = "7"
  198. MAGMULT.NUM.12 = 4.29981696    /* MagStep(8)   */
  199. MAGMULT.STR.12 = "8"
  200. MAGMULT.NUM.13 = 5.159780352   /* MagStep(9)   */
  201. MAGMULT.STR.13 = "9"
  202. magmult.num.14 = 0.913    /* magstep(-0.5) */
  203. magmult.str.14 = "-0.5"
  204. magmult.num.15 = 0.833    /* magstep(-1)   */
  205. magmult.str.15 = "-1"
  206. magmult.num.16 = 0.761    /* magstep(-1.5) */
  207. magmult.str.16 = "-1.5"
  208. magmult.num.17 = 0.694    /* magstep(-2)   */
  209. magmult.str.17 = "-2"
  210. magmult.num.18 = 0.634    /* magstep(-2.5) */
  211. magmult.str.18 = "-2.5"
  212. magmult.num.19 = 0.579    /* magstep(-3)   */
  213. magmult.str.19 = "-3"
  214. magmult.num.20 = 0.528    /* magstep(-3.5) */
  215. magmult.str.20 = "-3.5"
  216. magmult.num.21 = 0.482    /* magstep(-4)   */
  217. magmult.str.21 = "-4"
  218.  
  219. magmult.str.default = "???"
  220.  
  221. magstr = magmult.str.default
  222.  
  223. eps = 0.005        /* erlaubte Abweichung    */
  224.  
  225. DO i=1 to magmult.0
  226.   IF abs(magmult.num.i - mag) < eps THEN DO
  227.     mag    = magmult.num.i
  228.     magstr = magmult.str.i
  229.     LEAVE i
  230.   END
  231. END
  232.  
  233. /*
  234. ** Modes ... search the correct mode in the file MODEFILENAME (see above).
  235. */
  236. If ~Open('MODEFILE',MODEFILENAME,'READ') Then Do
  237.   Call Log("Can't find file "MODEFILENAME"!")
  238.   Exit 5
  239. End
  240.  
  241. /*
  242. ** 29.10.1993 Andreas Scherer: I keep this from version 0.91, because my
  243. ** configuration depends on argument PKDIR.
  244. ** In case this doesn't work, put in the following by Ulrich Wisser:
  245. **
  246. **   Do Until(XRES==HBASEDPI & YRES == VBASEDPI) | EOF('MODEFILE')
  247. **     LINE = ReadLn('MODEFILE')
  248. **     LINE = Readln('MODEFILE')
  249. **     LINE = Strip(Translate(LINE, ' ', '   '))
  250. **     MODE = Word(LINE,1)
  251. **     XRES = Word(LINE,2)
  252. **     YRES = Word(LINE,3)
  253. **   End
  254. **
  255. ** Maybe this could work with an additional entry
  256. **     PKDIR = Word(LINE,4)
  257. */
  258. Do Until (XRES == HBASEDPI & YRES == VBASEDPI) | EOF('MODEFILE')
  259.   Parse Value Translate(Readln('MODEFILE'),'','2009'X) With MODE XRES YRES PKDIR .
  260. End
  261.  
  262. If ~Close('MODEFILE') Then
  263.   Call Log("Can't close mode-file!")
  264.  
  265. If XRES ~= HBASEDPI | YRES ~= VBASEDPI Then Do
  266.   MODE = '' /* for pretty log-entry */
  267.   Call Log("Can't find matching mode!  Make an update in your "MODEFILENAME" file.")
  268.   Exit 5
  269. End
  270.  
  271. /*
  272. ** Produce the complete name of the file.
  273. */
  274. If PKFILENAME="" Then
  275.   PKNAME = PKDIR'/'FNTNAME'.'DPI'pk'    /* Changed - removed 'dpi' directory JöG. */
  276. Else
  277.   PKNAME = PKDIR||PKFILENAME
  278.  
  279. /*
  280. ** Look if the font already is there.
  281. */
  282. If Exists(PKNAME) Then Do
  283.   Say "The font "PKNAME" already exists!"
  284.   Say "Check your driver's configuration!"
  285.   Call Log(PKNAME" already exists; check your driver's configuration!")
  286.   Exit 5
  287. End
  288.  
  289. /*
  290. ** Install the options MetaFont is called with.
  291. */
  292.  
  293. /*
  294.  * Changed so that 'dc' fonts use the proper 'dx'
  295.  * base instead. [JöG 1994-10-19]
  296.  *
  297.  */
  298. if substr(FNTNAME, 1, 2)=='dc' then
  299.   FORMAT = 'dx'
  300. else
  301.   FORMAT = NORMALBASE
  302.  
  303.  
  304. If MAGSTR ~= MAGMULT.STR.DEFAULT Then
  305.   OPTIONS = "\mode:="MODE"; mag:=magstep("MAGSTR"); scrollmode; input "FNTNAME
  306. Else
  307.   OPTIONS = "\mode:="mode"; mag:="MAG"; scrollmode; input "FNTNAME
  308.  
  309. DUMMY = Pragma("directory","MF:")
  310. Address COMMAND
  311.  
  312. /*
  313. ** First: Create the GF-file and the TFM-file and the LOG-file
  314. ** by calling the METAFONT progam.  If anything below fails, you
  315. ** can proceed by hand; all necessary files will be present.
  316. */
  317. Say "Calling MetaFont with format: &"FORMAT" and startup commands: "
  318. Say "'"OPTIONS"'"
  319.  
  320. VIRMF '&'FORMAT' "'OPTIONS'"'
  321.  
  322. /*
  323. ** My version of METAFONT returns codes 0, 5, 10 or 20.
  324. ** Take appropriate actions.
  325. */
  326. ERRORCODE = RC
  327.  
  328. If 10 >= ERRORCODE Then Do    /* changed from 5 to 10 JöG */
  329.   If 0 < ERRORCODE Then
  330.     Say "Translation problem, MetaFont returned "ERRORCODE"."
  331.   Else
  332.     Say FNTNAME" translated without errors."
  333. End; Else Do
  334.   Say "Translation error, MetaFont returned "ERRORCODE"."
  335.   EDITSCRIPT = Word(MyGetEnv("MFREXXEDIT"),1)
  336.   If "" = EDITSCRIPT Then
  337.     EDITSCRIPT = 'MFEdit.rexx'
  338.   Say "Start editor for "FNTNAME" with "EDITSCRIPT"."
  339.   EDITSCRIPT FNTNAME 0
  340.   Exit 5
  341. End
  342.  
  343. /*
  344. ** Second: Create the PK-file by calling the GFtoPK program.
  345. ** This is done in the "MF:" directory, not in the final path.
  346. */
  347. GFTOPK FNTNAME'.'DPI'gf'
  348.  
  349. /*
  350. ** Don't delete the GF-file on failure.
  351. */
  352. If Exists(FNTNAME'.'DPI'pk') Then Do
  353.   Delete FNTNAME'.'DPI'gf'
  354.   /* FileNote FNTNAME'.'DPI'pk' ' "mode='MODE', magstep='MAGSTR'"' */
  355. End
  356.  
  357. /*
  358. ** Third: Create all needed directories and try to move the
  359. ** files appropriately.
  360. */
  361.  
  362. /*
  363. ** Don't include last '/' in PKDIR, makedir doesn't like it.
  364. */
  365. PKDIR2 = Left(PKDIR,LastPos("/",PKDIR)-1)
  366.  
  367. If ~Exists(PKDIR2) Then
  368.   If ~MakeDir(PKDIR2) Then Do
  369.     Call Log("MakeDir "PKDIR2" failed")
  370.     Exit 5
  371.   End
  372.  
  373. /*
  374. ** A '/' is required to exist in PKNAME
  375. */
  376.  
  377. /*
  378. ** Don't include last '/' in FULLDIR, makedir doesn't like it.
  379. */
  380. FULLDIR = Left(PKNAME,LastPos("/",PKNAME)-1)
  381.  
  382. If ~Exists(FULLDIR) Then
  383.   If ~MakeDir(FULLDIR) Then Do
  384.     Call Log("MakeDir "FULLDIR" failed")
  385.     Exit 5
  386.   End
  387.  
  388. /*
  389. ** Check the TFM-file; if it doesn't exist, move it there
  390. ** and delete it here.
  391. */
  392. If Exists(TEXTFM) & ~Exists(TEXTFM||FNTNAME'.tfm') Then Do
  393.   Copy FNTNAME'.tfm' TEXTFM clone
  394.   /* Protect TEXTFM||FNTNAME'.tfm' r */
  395. End
  396.  
  397. Delete FNTNAME'.tfm'
  398.  
  399. /*
  400. ** The following section makes a copy of the pk-file to MF:<mode>/PKFILENAME
  401. ** This is useful if you like to copy all new font-files to disks for
  402. ** future font-caching.  See the documentation for further details.
  403. */
  404. /*
  405. If ~Exists(MODE) Then Do
  406.   If ~MakeDir(MODE) Then Do
  407.     Call Log("Makedir "MODE" failed!")
  408.   End
  409. End
  410. If ~Exists(MODE'/'DPI) Then Do
  411.   If ~MakeDir(MODE'/'DPI) Then Do
  412.     Call Log("Makedir "MODE"/"DPI" failed!")
  413.   End
  414. End
  415. If Exists(MODE) Then
  416.   Copy FNTNAME'.'DPI'pk' MODE'/'PKFILENAME
  417. */
  418.  
  419. Copy FNTNAME'.'DPI'pk' PKNAME clone
  420. Delete FNTNAME'.'DPI'pk'
  421. /* Protect PKNAME r */
  422.  
  423. /*
  424.  * I want the .pk files in different directories
  425.  * than the PasTeX people do. [JöG 1994-10-19]
  426.  *
  427.  */
  428.  
  429. /* Rename PKNAME TO 'TeX:pk/'HBASEDPI'x'VBASEDPI'/' */
  430.  
  431.  
  432. /*
  433. ** Copy/Delete instead Rename to overwrite existing logfile (e.g., from
  434. ** a failed call of MakeTeXfont). Replace by 'move' if you have ARP:
  435. ** i.e., add a line here ``copy = "move" or "mv"''.  This seems to be
  436. ** the case for Ulrich Wisser in Version 1.0, as he uses "move" here.
  437. ** I still assume that most people want to use this script with the
  438. ** original WorkBench, so double moving would cause this to crash.
  439. ** Also, copy/delete unlike move works between devices, too.
  440. */
  441. Copy FNTNAME'.log' LOGDIR'/'FNTNAME'.'DPI'log'
  442. Delete FNTNAME'.log'
  443.  
  444. ELAPSED = Time("ELAPSED")
  445. Call Log("created in "ELAPSED%3600":"Right(ELAPSED%60//60,2,'0')":"Right(ELAPSED%1//60,2,'0'))
  446.  
  447. Say '---'||'07'x
  448.  
  449. Exit 0
  450.  
  451. /*
  452. ** Log-function
  453. */
  454. LOG: Procedure Expose LOGNAME FNTNAME MODE HBASEDPI VBASEDPI DPI MAGSTR
  455. Parse Arg MSG
  456.  
  457. MESSAGE = Date()" "Time()": "FNTNAME" for "MODE" ("HBASEDPI","VBASEDPI") with "DPI" dpi (mag="MAGSTR") "'0A'X || MSG
  458. Say MESSAGE
  459.  
  460. If ~Open(LOGFILE,LOGNAME,'Append') Then Do
  461.   Say "Can't open logfile!"
  462.   Return
  463. End
  464.  
  465. DUMMY = Writeln(LOGFILE,MESSAGE)
  466. If ~Close(LOGFILE) Then
  467.   Say "Can't close logfile!"
  468.  
  469. Return
  470.  
  471. /*
  472. ** Signal-functions.
  473. */
  474. FAILURE:
  475.   DOLINE = 'call log("errorlevel 'rc' in line 'sigl': "'sourceline(sigl)')'
  476.   Interpret(DOLINE)
  477.   If Exists(FNNAME'.log') Then Do
  478.     Copy FNTNAME'.log' FNTNAME'.'DPI'log'
  479.     Delete FNTNAME'.log'
  480.   End
  481.   Exit 1
  482.  
  483. BREAK_C:
  484. BREAK_D:
  485.   Call Log "execution aborted!"
  486.   If Exists(FNTNAME'.'DPI'gf') Then
  487.     DUMMY = Delete FNTNAME'.'DPI'gf'
  488.   If Exists(FNTNAME'.log') Then
  489.     DUMMY = Delete FNTNAME'.log'
  490.  
  491.   Exit 1
  492.